<template>
  <div class="DecRoot">
    <el-card class="box-card">
      <div class="headerBox">
        <div class="leftBox">
          <el-radio-group v-model="radio1" @change="selectPage">
            <el-radio-button
              :label="index"
              v-for="(item, index) in tab"
              :key="index"
              >{{ item.name }}</el-radio-button
            >
          </el-radio-group>
        </div>
        <el-button
          type="primary"
          icon="el-icon-plus"
          @click="dialogVisibleB = true"
          plain
          :disabled="!arrId.length"
          >批量编辑</el-button
        >
      </div>
    </el-card>
    <el-card class="box-card newCard">
      <el-table
        :data="tableData"
        style="width: 100%"
        height="66vh"
        header-cell-class-name="tableHeader"
        stripe
        @selection-change="handleSelectionChange"
      >
        <el-table-column type="selection" width="55"> </el-table-column>
        <el-table-column label="序号" type="index" width="50">
        </el-table-column>
        <el-table-column prop="adPositionText" label="广告名称" width="200">
        </el-table-column>
        <el-table-column
          prop="description"
          label="广告说明"
          width="300"
          :show-overflow-tooltip="true"
        >
        </el-table-column>
        <el-table-column
          prop="imageUrlSize"
          label="图片比例"
          :show-overflow-tooltip="true"
        >
        </el-table-column>
        <el-table-column
          prop="applyCreateTime"
          label="报名时间"
          :show-overflow-tooltip="true"
        >
          <template slot-scope="scope">
            {{ scope.row.applyCreateTime }} - {{ scope.row.applyEndTime }}
          </template>
        </el-table-column>
        <el-table-column prop="applyCreateTime" label="广告报名时间周期">
          <template slot-scope="scope"> {{ scope.row.applyDay }}天 </template>
        </el-table-column>
        <el-table-column
          prop="adCreateTime"
          label="开始时间"
          :show-overflow-tooltip="true"
        >
          <template slot-scope="scope">
            {{ scope.row.adCreateTime }} - {{ scope.row.adEndTime }}
          </template>
        </el-table-column>

        <el-table-column prop="adCreateTime" label="广告开始时间周期">
          <template slot-scope="scope"> {{ scope.row.adDay }}天</template>
        </el-table-column>
        <el-table-column prop="price" label="广告费用" width="100">
        </el-table-column>
        <el-table-column prop="adNumber" label="广告数量" width="100">
        </el-table-column>

        <el-table-column prop="address" label="操作" width="100">
          <template slot-scope="scope">
            <el-tooltip
              class="item"
              effect="dark"
              content="编辑"
              placement="top"
            >
              <img
                src="@/assets/image/icon/edit.png"
                @click="edit(scope.row)"
                class="iconImg"
                alt=""
              />
            </el-tooltip>
          </template>
        </el-table-column>
      </el-table>
      <!-- <div class="pagination">
        <div></div>
        <el-pagination
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :page-sizes="[10, 20, 50, 100]"
          :page-size="1"
          layout="total, sizes, prev, pager, next, jumper"
          :total="total"
        >
        </el-pagination>
      </div> -->
    </el-card>
    <el-dialog :visible.sync="dialogVisible" width="500" class="newDialog">
      <div class="DiaLogHeader">
        <div class="titlebOX">编辑广告</div>
        <div class="chahao" @click="dialogVisible = false">
          <i class="el-icon-close"></i>
        </div>
      </div>
      <el-divider></el-divider>
      <div style="padding: 10px">
        <el-form ref="form" :model="form" label-width="auto">
          <el-form-item label="广告报名时间周期">
            <el-input v-model="form.applyDay"></el-input>
          </el-form-item>
          <el-form-item label="广告开始时间周期">
            <el-input v-model="form.adDay"></el-input>
          </el-form-item>
          <el-form-item label="广告费用" v-if="!form.priceFlag">
            <el-input v-model="form.price"></el-input>
          </el-form-item>
          <div v-else>
            <el-form-item
              :label="item.adPositionText+'价格'"
              v-for="(item, index) in form.advertisementVOList"
              :key="index"
            >
              <el-input v-model="item.price"></el-input>
            </el-form-item>
          </div>
          <el-form-item label="广告说明">
            <el-input
              v-model="form.description"
              type="textarea"
              :autosize="{ minRows: 4 }"
            ></el-input>
          </el-form-item>
        </el-form>
      </div>
      <div class="btnBox">
        <el-button type="primary" @click="updateAdvertisement"> 确定</el-button>
        <el-button @click="dialogVisible = false"> 取消</el-button>
      </div>
    </el-dialog>
    <el-dialog :visible.sync="dialogVisibleB" width="30%" class="newDialog">
      <div class="DiaLogHeader">
        <div class="titlebOX">批量编辑广告</div>
        <div class="chahao" @click="dialogVisibleB = false">
          <i class="el-icon-close"></i>
        </div>
      </div>
      <el-divider></el-divider>
      <div style="padding: 10px">
        <el-form ref="form" :model="formB" label-width="auto">
          <el-form-item label="广告报名时间周期">
            <el-input v-model="formB.applyDay"></el-input>
          </el-form-item>
          <el-form-item label="广告开始时间周期">
            <el-input v-model="formB.adDay"></el-input>
          </el-form-item>
        </el-form>
      </div>
      <div class="btnBox">
        <el-button type="primary" @click="updateBatchAdvertisement">
          确定</el-button
        >
        <el-button @click="dialogVisibleB = false"> 取消</el-button>
      </div>
    </el-dialog>
  </div>
</template>
  
  <script>
import {
  selectPage,
  updateAdvertisement,
  updateBatchAdvertisement,
  selectAdInfoByPosition,
} from "@/api/AdvertisingManagement";
export default {
  name: "login",
  data() {
    return {
      dialogVisibleB: false,
      radio1: 0,
      dialogVisible: false,
      tab: [
        {
          name: "首页页面",
        },
        {
          name: "商品库页面",
        },
        {
          name: "当季新品页面",
        },
        {
          name: "当季热卖页面",
        },
        {
          name: "直播选品页面",
        },
      ],
      dialogVisible: false,
      total: 2,
      formInline: {
        pageNum: 1,
        pageSize: 10,
        sbid: "",
        zjmc: "",
      },
      form: {},
      tableData: [{}],
      arrId: [],
      formB: {},
    };
  },
  created() {
    this.selectPage();
  },
  methods: {
    //获取广告详情
    selectAdInfoByPosition(row) {
      selectAdInfoByPosition({
        adPosition: row.adPosition,
      }).then((data) => {
        this.form = data.data;
        this.dialogVisible = true;
      });
    },
    //批量编辑广告信息
    updateBatchAdvertisement() {
      let arr = [];
      this.arrId.forEach((item) => {
        arr.push(item.adPosition);
      });
      let ids = arr.join(",");
      updateBatchAdvertisement(this.formB, ids).then((data) => {
        if (data.code == 200) {
          this.$message({
            message: "修改成功",
            type: "success",
          });
          this.dialogVisibleB = false;
          this.selectPage();
          this.formB = {};
        }
      });
    },
    handleSelectionChange(val) {
      console.log(val);
      this.arrId = val;
    },
    //修改广告信息
    updateAdvertisement() {
      updateAdvertisement(this.form).then((data) => {
        if (data.code == 200) {
          this.$message({
            message: "修改成功",
            type: "success",
          });
          this.dialogVisible = false;
          this.selectPage();
        }
      });
    },
    //编辑广告
    edit(row) {
      this.selectAdInfoByPosition(row);
    },
    //获取广告列表
    selectPage() {
      selectPage({
        keyword: this.radio1,
        pageNumber: 1,
        pageSize: 10,
      }).then((data) => {
        this.tableData = data.data.list;
      });
    },
    //分页
    handleSizeChange(val) {
      this.formInline.pageSize = val;
      this.getList();
    },
    handleCurrentChange(val) {
      this.formInline.pageNum = val;
      this.getList();
    },
  },
};
</script>
  
  <style scoped lang="scss">
.btnBox {
  display: flex;
  justify-content: center;
  background: #fff;
  box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
  position: absolute;
  bottom: 0;
  width: 100%;
  padding: 10px 0;

  .btnImg {
    width: 14px;
    height: 14px;
    vertical-align: middle;
  }
}

.DecRoot {
  padding: 20px;
  padding-left: 5px;
  padding-bottom: 0;

  .newCard {
    height: 75vh;
    margin-top: 20px;
  }

  /deep/ .el-button {
    padding: 9px 15px;
  }

  .el-card {
    .headerBox {
      display: flex;
      justify-content: space-between;
      align-items: center;

      .leftBox {
        display: flex;
        align-items: center;

        /deep/ .el-form-item {
          margin-bottom: 0;
        }

        /deep/ .el-input--suffix {
          width: 200px;
        }
      }
    }

    /deep/ .tableHeader {
      background: #edf3ff;
      font-weight: 700;
      color: #666666;
    }

    .iconImg {
      width: 20px;
      height: 20px;
      cursor: pointer;
      margin-right: 10px;
    }

    .pagination {
      display: flex;
      justify-content: space-between;
      margin-top: 10px;

      /deep/ .el-pagination__editor.el-input .el-input__inner {
        height: 28px !important;
      }

      /deep/ .el-input--mini .el-input__inner {
        height: 28px !important;
      }
    }
  }
}
</style>
<style scoped lang="scss">
.newDialog {
  /deep/ .el-divider {
    margin: 0px;
  }
  /deep/ .el-dialog__header {
    padding: 0;
  }
  /deep/ .el-form-item__content {
    width: 75%;
  }
  /deep/ .el-select {
    width: 100%;
  }
  /deep/ .tableHeader {
    background: #edf3ff;
    font-weight: 700;
    color: #666666;
    padding: 5px 0;
  }
  .btnBox {
    display: flex;
    justify-content: center;
    background: #fff;
    box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
    position: absolute;
    bottom: 0;
    width: 100%;
    padding: 10px 0;
    .btnImg {
      width: 14px;
      height: 14px;
      vertical-align: middle;
    }
    /deep/ .el-button {
      padding: 10px 20px;
    }
  }
  .DiaLogHeader {
    display: flex;
    padding: 10px 20px;
    justify-content: space-between;
    .titlebOX {
      font-size: 16px;
      font-weight: 700;
    }
    .chahao {
      width: 20px;
      height: 20px;
      background-image: url("@/assets/image/icon/chahao.png");
      background-size: 100% 100%;
      text-align: center;
      line-height: 20px;
      color: #e65f00;
      cursor: pointer;
    }
  }
  /deep/ .el-input {
    width: 100% !important;
  }
}
/deep/ .el-dialog__header {
  font-weight: 700;
}
/deep/ .demo-ruleForm {
  padding: 10px;
}

/deep/ .el-form-item {
  margin-bottom: 8px;
}
/deep/ .el-form-item__error {
  z-index: 99;
}
/deep/ .el-dialog__body {
  padding: 0;
  padding-top: 10px;
  padding-bottom: 60px;
}
.dialogTextBox {
  font-size: 14px;
  color: #000000;
}
</style>
  